<?php

namespace app\api\controller\im;

use app\api\controller\im\Base;
use app\api\validate\im\UserSigValidate;
use app\logic\im\UserSigLogic;

class UserSig extends Base
{
    protected UserSigLogic $userSigLogic;

    public function initialize(): void
    {
        parent::initialize();
        $this->userSigLogic = new UserSigLogic();
    }

    /**
     * 创建令牌
     *
     * 用于登录腾讯IM
     */
    public function create()
    {
        // 实例化验证器对象，用于后续的参数验证
        $this->check(new UserSigValidate(), $this->request->post());

        $data = $this->userSigLogic->genUserSig($this->auth->id); // 一天有效期的令牌

        $this->log('user id ' . $this->auth->id . ' create user sig: ' . $data['userSig']);

        // 返回成功发布动态的消息
        $this->success(__('success'), $data);
    }
}